package com.TreeMap;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class TreeMapTest3 {
    public static void main(String[] args) {
        //先创建字符串：
        String s = "aababcabcdabcde";
        TreeMap<Character,Integer> tm = new TreeMap<>();


        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            //找一个集合将字符存入进去：
            if(tm.containsKey(c)){
                int count = tm.get(c);
                count++;
                tm.put(c,count);
            }
            else {
                tm.put(c,1);
            }

        }

        //遍历集合：用键值对对象来试试：
        Set<Map.Entry<Character, Integer>> entries = tm.entrySet();
        for (Map.Entry<Character, Integer> entry : entries) {
            System.out.print(entry.getKey() + "(" + entry.getValue() + ")");

        }


    }
}
